<?php 
App::import('Model','features.Feature');
//App::import('Model','categories.Category');
//App::import('Model','discovers.DiscoverCategory');
class FeaturesController extends AppController {
	var $name = 'Features';
	var $uses = array('features.Feature');
	var $helpers = array('text');
	var $view = 'Theme';
	var $theme = 'qat';
	var $layout = 'news';
	//var $layout	= 'default';
	/**
	 @var $model
	 @brief Thông tin về model, được sử dụng trong trường hợp override thông tin của danh mục
	 */
	var $models = array(
		'Page'		=>	array(
			'plugin'	=>	'features',
			'name'		=>	'Feature'
		)
	);
	function beforeFilter() {
		parent::beforeFilter();
		$this->configs = $this->{$this->models['Page']['name']}->loadConfig();
		$this->set('configs', $this->configs);
		//$this->category_root_id = $this->configs['Category']['root_id'];
	}
	
	function index() {
		$this->paginate[$this->models['Page']['name']] = array(
			'limit' => 5,
			'order'	=> 'created desc'
		);
		$data = $this->paginate($this->models['Page']['name']);
		$this->set('pages', $data);
	}

	function view($alias = null) {
		$detail = $this->{$this->models['Page']['name']}->find('first', array(
			'conditions'	=>	array(
				"{$this->models['Page']['name']}.alias" => $alias,
                "is_published"   => 1
			),
			'fields'		=>	array('id', 'title', 'alias', 'description', 'content', 'image', 'created'),
			'contain'		=> array(),
		));
		$others = $this->{$this->models['Page']['name']}->find('all', array(
			'conditions'	=>	array(
				"{$this->models['Page']['name']}.alias <>" => $alias,
                "is_published"   => 1
			),
			'fields'		=>	array('id', 'title', 'content','image', 'description', 'alias', 'created'),
			'order'			=>	array(
									"{$this->models['Page']['name']}.priority desc",
									"{$this->models['Page']['name']}.created desc"
								),
			'contain'		=> array(),
            'limit'			=> 5,
		));
		$this->set('detail', $detail);
		$this->set('others', $others);
	}
	
}	
?>